import { Http } from '@/utils';

export async function fetchOrderLists(params: {}) {
  const { errorCode, data } = await Http({
    url: '/orders',
    params,
  });

  if (errorCode === 0) {
    return data;
  }

  return [];
}

export async function fetchOrderDetail(params: { id: string | number }) {
  const { id } = params;
  const { errorCode, data } = await Http({
    url: `/order/${id}`,
  });

  if (errorCode === 0) {
    return data;
  }
  return null;
}

export async function fetchAddOrder(params: { id: string | number }) {
  const { id } = params;
  const ret = await Http({
    url: `/order/${id}/add`,
    method: 'POST',
  });

  return ret;
}

export async function fetchDeleteOrder(params: { id: string | number }) {
  const { id } = params;
  const ret = await Http({
    url: `/order/${id}/del`,
    method: 'DELETE',
  });

  return ret;
}

export async function fetchPayOrder(params: { id: string | number }) {
  const { id } = params;
  const ret = await Http({
    url: `/order/${id}/pay`,
    method: 'POST',
  });

  return ret;
}
